package com.honey.nuts;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class HoneynutsActivity extends Activity implements OnClickListener {
	/** Called when the activity is first created. */
	Button b1;
	Button b2;
	EditText box;
	String txtFileName;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		b1 = (Button) findViewById(R.id.b1);
		box = (EditText) findViewById(R.id.editText1);
		b1.setOnClickListener(this);
		txtFileName = "sam.txt";
		b2 = (Button) findViewById(R.id.b2);
		b1.setOnClickListener(this);
		


	}
	private void CreateTxtFile(){
		OutputStreamWriter out;
		try {
			out = new OutputStreamWriter(openFileOutput("sam.txt", 0));
			out.write("hi");
			out.close();
		} catch (Exception e) {

			e.printStackTrace();
		}

	}

	private void loadTxtFile(String txtFileName) {
		try {
			InputStream in = openFileInput("sam.txt");
			if(in!=null){
				BufferedReader br = new BufferedReader(new InputStreamReader(in));

				String str = "";


				while ((str = br.readLine()) != null) {


				}


				Toast.makeText(this, str, Toast.LENGTH_LONG).show();

			}
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}


	}
	public void onClick(View v) {
		box.getText().toString();
		if(v.equals(b1)){
			Toast.makeText(this, "file created", Toast.LENGTH_LONG).show();
		}
		if(v.equals(b2)){
			loadTxtFile("sam.txt");
		}
	}
}